import { Permission } from '@/type/Permission';

const persistKey = 'loggedUserPermissions';
let data: Permission[] | null = null;

function set(permissions: Permission[]) {
    data = permissions || [];

    if (permissions) {
        window.localStorage.setItem(persistKey, JSON.stringify(permissions));
    } else {
        window.localStorage.removeItem(persistKey);
    }
}

function get(): Permission[] {
    return data || JSON.parse(window.localStorage.getItem(persistKey) || '') || [];
}

export default {
    set,
    get,
};
